Programmatically setting a user's timezone ("My Regional Settings")
I'm working on a large, global extranet. Since the site features a lot ofcalendar data, it's crucial that we have all of our users set in the correct timezone. Two questions:
1. Does sharepoint automatically grab timezone information from active directory?
2. Can I programmatically set a user's timezone (my app is dual-zoned with a large percentage of users not in active directory but rather in SQL)? If so, if someone could point me to the proper namespace and maybe even provide a code snippet it would be very much appreciated.
Thanks!
Allan
UPDATE: I've done some more research and have found SPUser.RegionalSettings but, from what I can tell, RegionalSettings has no properties fot time zone.
ANOTHER UPDATE: Well,I was able to figure out that you CAN in fact programatically set a user's timesone. And yes, the way you do it is using SPUser.RegionalSettings. It turns out that the SDK Documentation (link) is incorrect and there is in fact a TimeZone property in SPUser.RegionalSettings. I have alerted my contacts at Microsoft to the error.
I have also done some investigation re the first question and, from what I can tell, timezone does NOT appear to come from active directory although perhaps someone else can clarify.
March 31st, 2007 9:33pm
Hi Allan,
Well,I was able to figure out that you CAN in fact programatically set a user's timesone. And yes, the way you do it is using SPUser.RegionalSettings. It turns out that the SDK Documentation (link) is incorrect and there is in fact a TimeZone property in SPUser.RegionalSettings. I have alerted my contacts at Microsoft to the error.
I have also done some investigation to your first question and, from what I can tell, timezone does NOT appear to come from active directory although perhaps someone else can clarify.
Yours,
Allan
Free Windows Admin Tool Kit Click here and download it now
April 2nd, 2007 9:09pm
Note the SPWeb parameter in the constuctor of the
SPRegionalSettings class. Given that you say you've a "large, global extranet", you'll need to be mindful in a large amount if sites, if your implementation is large.Michael Mukalian | Jan 2010 - Dec 2010 MVP SharePoint Services | MCTS: MOSS 2007 Configuration | http://www.mukalian.com/blog
July 2nd, 2011 8:14am
$regSettings = new-object Microsoft.SharePoint.SPRegionalSettings($web, $true);
$regSettings = new-object Microsoft.SharePoint.SPRegionalSettings($web, $true);
$regSettings.TimeZone.Id = 10 // New York - Eastern
$currentUser.RegionalSettings = $regSettings
$currentUser.Update();
This is how you do it with powershell. The same is good for C#.
Free Windows Admin Tool Kit Click here and download it now
July 2nd, 2011 4:31pm